package perInfo;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserCookie {
	private Cookie userName;
	private Cookie userPassword;
	
	public static String getUserCookie(HttpServletRequest request,String name){
		Cookie[] cookies=request.getCookies();
		if(cookies==null)
			return null;
		for(Cookie cookie : cookies){
			if(cookie.getName().equals(name)){
				return cookie.getValue();
			}
		}
		return null;
	}
	
	public static void setUserCookie(HttpServletResponse response,String name,String value){
		Cookie cookie = new Cookie(name,value);
		cookie.setPath("/");
		response.addCookie(cookie);

	}
	
	public static void killUserCookie(HttpServletResponse response,String name){
		Cookie cookie = new Cookie(name,null);
		cookie.setMaxAge(0);
		cookie.setPath("/");
		response.addCookie(cookie);
	}
	
	public void setUserName(Cookie userName) {
		this.userName = userName;
	}
	public Cookie getUserName() {
		return userName;
	}
	public void setUserPassword(Cookie userPassword) {
		this.userPassword = userPassword;
	}
	public Cookie getUserPassword() {
		return userPassword;
	}
}
